package forum.repository;

import forum.domain.Resources;
import forum.domain.RoleResources;
import forum.service.tools.BaseSearch;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2017/4/1.
 */
public interface RoleResourcesRepository extends JpaRepository<RoleResources, Integer>, JpaSpecificationExecutor<RoleResources> {

    @Query(value ="select * from resources,role,role_resources where role_resources.roleid=role.roleid and role_resources.resourcesid=resources.resourcesid and role.rolename = ?1", nativeQuery = true)
    List<RoleResources> findByRolename(String rolename);


    @Transactional
    @Modifying
    @Query(value ="delete from role_resources where role_resources.roleid = ?1", nativeQuery = true)
    void deleteByRoleid(Integer id);

    @Transactional
    @Modifying
    @Query(value ="delete from role_resources where role_resources.resourcesid = ?1", nativeQuery = true)
    void deleteByResourcesid(Integer id);

}
